import { IsInt, ValidateNested, IsNotEmpty, Length } from 'class-validator';
import { Transform, Type } from 'class-transformer';

class Hobby {
  @IsNotEmpty({
    message: '$property 兴趣名称不能为空',
  })
  name: string;

  @IsNotEmpty({
    message: '$property 兴趣类型不能为空',
  })
  type: string;
}

export class CreateHttpExampleDto {
  @Transform(({ value }) => value?.trim())
  @IsNotEmpty()
  @Length(2, 20)
  name: string;

  @IsInt()
  age: number;

  @ValidateNested()
  @Type(() => Hobby)
  hobbies: Hobby[];

  @ValidateNested()
  @Type(() => Hobby)
  hobby: Hobby;
}
